#!/bin/sh

## Directories ----------------------------
DIR=`pwd`
FONT_DIR="$HOME/.local/share/fonts"
# wallpaper_dir="$HOME/wallpaper"
CONF="$HOME/.config"
BSPWM_DIR="$CONF/bspwm"
script_DIR="$CONF/script"
alacritty_DIR="$CONF/alacritty"

# 安装 Fonts
install_fonts() {
	echo "[*] Installing fonts..."
	if [[ -d "$FONT_DIR" ]]; then
		cp -rf $DIR/fonts/* "$FONT_DIR"
	else
		mkdir -p "$FONT_DIR"
		cp -rf $DIR/fonts/* "$FONT_DIR"
	fi
	echo "[*] Updating font cache..."
	fc-cache
}

# 修改权限
change_bspwm_script() {
    echo "[*] Change bspwm script permission..." 
    chmod -R 755 $DIR/bspwm/bin
    chmod -R 755 $DIR/bspwm/rofi/bin
    chmod 755 $DIR/bspwm/bspwmrc
}

# 复制壁纸
copy_wallpaper() {
	echo "[*] Copy wallpaper..."
	sudo mkdir -p /usr/share/backgrounds
	sudo cp -rf $DIR/wallpaper/* /usr/share/backgrounds
}

# 复制 bspwm 的配置
copy_bspwm() {
	if [[ -d "$BSPWM_DIR" ]]; then
		echo "[*] Creating a backup of your bspwm configs..."
		mv "$BSPWM_DIR" "${BSPWM_DIR}.${USER}"
	fi
	echo "[*] Installing bspwm configs..."
	{ mkdir -p "$BSPWM_DIR"; cp -rf $DIR/bspwm/* "$BSPWM_DIR"; }
	cp -rf $DIR/bspxinit ~/.xinitrc
	cp -rf $DIR/betterlockscreenrc $CONF
	cp -rf $DIR/mpd $CONF
	cp -rf $DIR/.profile ~/.profile
	cp -rf $DIR/.Xresources ~/.Xresources

	if [[ -f "$BSPWM_DIR/bspwmrc" ]]; then
		echo "[*] Successfully."
		exit 0
	else
		echo "[!] Failed."
		exit 1
	fi
}


case $1 in 
    bspwm)
	install_fonts
	copy_wallpaper
    change_bspwm_script
    copy_bspwm
    ;;
    hyprland)
    echo "hyprland"

esac
